<div class="layui-hide" id='enian-nav-bar'>
	<!-- 默认选中菜单左侧 -->
	<a type='menu' data-url=""></a>
	<a data-url="">我的应用</a>
</div>
<style type="text/css">
	body{
		background: #f2f2f2;
	}
	.app-icon{
		background: darkslategray;
		border-radius: 5px;
		height: 25px;
		width: 25px;
		font-size: 10px;
		line-height: 25px;
		text-align: center;
		color: white;
		margin-right: 15px;
	}
	.son-app{
		/*background: red;*/
		text-align:center;
	}
	.card-page{
		margin-right: 20px;
	}
	.card-page .point{
		width: 12px;
		height: 12px;
		background: darkgray;
		padding: 0;
		border-radius: 50%;
	}
	.cursor-pointer{
		cursor: pointer;
	}
	
	
	
	.son-app .icon{
		background: #6595ed;
		margin:0 auto;
		display: inline-block;
		height: 50px;
		width: 50px;
		line-height: 50px;
		border-radius: 10px;
		font-size: 20px;
		color: white;
	}
	.son-app .text{
		font-size: 10px;
	}
	.son-app-list{
		overflow: auto;
		height: 148px;
	}
</style>

<!-- 应用列表 -->
<div id="applist-body" class="applist-body layui-row layui-col-space20"></div>




<script type="text/javascript">
	layui.config({base: '/static/layui_extends/', })
	layui.use(['treetable','jquery','layer','form','laytpl','mouseRightMenu'],function(){
		var $ = layui.jquery;	
		var laytpl =layui.laytpl;
		var layer =layui.layer;
		var mouseRightMenu = layui.mouseRightMenu;

		var elem='#applist-body';
		var appData={$data};
		var appids=[];
		$.each(appData, function(i,k) {
			render_app(k,i)
		});
		
		render_son_app()//渲染子应用
		
		
		//渲染App
		function render_app(obj,index){
			appids.push(obj.appid);
			var title=obj.note ||'';
			var appname_icon = obj.name.substr(0,1);
			var html = '<div class="layui-col-xs12 layui-col-sm6 layui-col-md4">'
							+'<div class="layui-card">'
								+'<div class="layui-card-header">'
								+	'<div class="app-icon layui-inline">'
								+		appname_icon
								+	'</div>'
//								+	'<div class="card-page layui-inline layui-layout-right">'
//								+			<div class="point layui-inline cursor-pointer"></div>
//								+			<div class="point layui-inline cursor-pointer"></div>
//								+			<div class="point layui-inline cursor-pointer"></div>
//								+	'</div>'
								+	'<div class="layui-inline cursor-pointer" title="'+title+'">'
								+		obj.name
								+	'</div>'
								+'</div>'
								+'<div class="layui-card-body son-app-list" id="son-app-list'+obj.appid+'">'
									 +'<ul class="layui-row layui-col-space10"></ul>'
								+'</div>'
							+'</div>'
						+'</div>';
			$(elem).append(html);
		}
		
		//渲染子app
		function render_son_app(){
			$.ajax({
				type:"post",
				data:{appids:appids},
				url:"{:url('myAppList',['t'=>2])}",
				async:true,
				success:function(r){
					var data = r.data;
					$.each(data, function(i,k) {
						$.each(k, function(index,key) {
							$(elem + ' #son-app-list'+key.appid).append(get_son_app_html(key));
						});
						
					});
					listen_son_click();//监听左键
					listen_right_click();//监听右键
				}
			});
		}
		
		function get_son_app_html(obj){
			var appname_icon = obj.name.substr(0,1);
			var title=obj.note ||'';
			var html = 	'<div class="layui-col-md4 layui-col-xs4">'
							+'<div class="son-app cursor-pointer" data-url="'+obj.url+'" title="'+title+'">'
								+'<div class="icon">'
								+	appname_icon
								+'</div>'
								+'<div class="text layui-elip">'
								+	obj.name
								+'</div>'
							+'</div>'			        	
						+'</div>';
			return html;
		}
		
		function listen_son_click(){
			$(elem + ' .son-app').click(function(){
				enianAdmin.go($(this).data('url'));
			})
		}


		function listen_right_click(){
			$(elem + ' .son-app').bind("contextmenu", function(){
				// console.log("屏蔽右鍵")
				
				var menu_data=[
			            {'data':{"url":$(this).data('url'),"win_title":$(this).children('.text').html()},'type':1,'title':'窗口打开'}
			        ]
				
				mouseRightMenu.open(menu_data,false,function(d){
		            // console.log(d)//输出：{'data':data,'type':4,'title':'粘贴'}
		            if(d.type==1){
		            	var url = enianAdmin.url(d.data.url);
						var param = url.params;
						var newUrl ='?PAGE_TYPE=2';
						for (var k in param) {
							newUrl+='&'+k+'='+param[k];
						}

		            	enianAdmin.openWindow({
						  	url: url.path+newUrl,
							title: d.data.win_title,
						  	area:['700px', '500px']
						})
		            }
				})
			    return false;
			})
		}

	})
</script>
	